﻿var MARKUP_BOLD = "b"; var MARKUP_CODE = "code"; var MARKUP_FILE = "file"; var MARKUP_ITALIC = "i"; var MARKUP_LINK = "link"; var MARKUP_LIST = "list"; var MARKUP_UNDERLINE = "u"; $.fn.addMarkup = function (i) { return this.each(function () { var a = this.value.length; var b = this.selectionStart; var c = this.selectionEnd; var d = this.value.substring(b, c); var e = (i == MARKUP_FILE || i == MARKUP_LINK) ? "[" + i + " url=\"\"]" + d + "[/" + i + "]" : "[" + i + "]" + d + "[/" + i + "]"; this.value = this.value.substring(0, b) + e + this.value.substring(c, a); var f = i.length; var g = b + f + 2; if (i == MARKUP_FILE || i == MARKUP_LINK) g = b + f + 7; if (this.setSelectionRange) { this.focus(); this.setSelectionRange(g, g) } else if (this.createTextRange) { var h = this.createTextRange(); h.collapse(true); h.moveEnd("character", g); h.moveStart("character", g); h.select() } }) };